package com.lzy.cloud.ticket.train.servcie.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lzy.cloud.ticket.train.dtos.TrainOrderDto;
import com.lzy.cloud.ticket.train.entity.TrainOrder;
import com.lzy.cloud.ticket.train.mapper.TrainOrderMapperExt;
import com.lzy.cloud.ticket.train.servcie.TrainOrderService;
import com.lzy.framework.core.orm.db.Pager;
import com.lzy.framework.core.utils.DozerUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by WIN7 on 2018/6/1.
 */
@Service
public class TrainOrderServiceImpl implements TrainOrderService {

    @Autowired
    TrainOrderMapperExt trainOrderMapperExt;

    @Override
    public PageInfo<TrainOrderDto> queryTrainOrderList(Pager pager, TrainOrderDto trainOrderDto) {
        if (pager != null)
            PageHelper.startPage(pager.getPageNum(), pager.getPageSize());
        List<TrainOrderDto> list = trainOrderMapperExt.queryTrainOrderList(trainOrderDto);
        return new PageInfo<>(list);
    }

    @Override
    public TrainOrderDto queryTrainOrderByCondition(String customId) {
        return trainOrderMapperExt.queryTrainOrderByCondition(customId);
    }

    @Override
    public Long createTrainOrder(TrainOrderDto trainOrderDto) {
        TrainOrder trainOrder = DozerUtils.map(trainOrderDto,TrainOrder.class);
        return trainOrderMapperExt.insertSelective(trainOrder)>0 ? trainOrder.getId() :null;
    }

    @Override
    public boolean updateTrainOrder(TrainOrderDto trainOrderDto) {
        TrainOrder trainOrder = DozerUtils.map(trainOrderDto,TrainOrder.class);
        return trainOrderMapperExt.updateByPrimaryKeySelective(trainOrder)>0;
    }
}
